package experiment8;

import java.util.Scanner;

public class No_2 {
    public static void main(String []args) throws NumberFormatException {
        Scanner input=new Scanner(System.in);
        while (true){
            System.out.println("请输入一个二进制数：");
            System.out.println(bin2Dec(input.nextLine()));
        }
    }

    public static int bin2Dec(String binaryString) throws NumberFormatException{
        int res=0;
        try {
            res=Integer.parseInt(binaryString,2);
        }
        catch (java.lang.NumberFormatException e){
            throw new NumberFormatException();
        }
        return res;
    }
}

class NumberFormatException extends Exception{
    public NumberFormatException(){
        super("不是二进制字符串");
    }
}